'''
copy

'''
import sys,math
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class ClipBoard(QDialog):
    def __init__(self):
        super(ClipBoard, self).__init__()
        textCopyButton = QPushButton('TCopy')
        textPasteButton = QPushButton('TPaste')

        htmlCopyButton = QPushButton('HCopy ')
        htmlPasteButton = QPushButton('HPaste')

        imageCopyButton = QPushButton('ICopy ')
        imagePasteButton = QPushButton('IPaste')

        self.textLabel = QLabel('默认文本')
        self.imageLabel = QLabel()
        self.imageLabel.setPixmap(QPixmap('./python.png'))

        layout = QGridLayout()
        layout.addWidget(textCopyButton, 0, 0)
        layout.addWidget(htmlCopyButton, 0, 1)
        layout.addWidget(imageCopyButton, 0, 2)
        layout.addWidget(textPasteButton, 1, 0)
        layout.addWidget(htmlPasteButton, 1, 1)
        layout.addWidget(imagePasteButton, 1, 2)

        layout.addWidget(self.textLabel,2, 0, 1, 2)
        layout.addWidget(self.imageLabel, 2, 2)

        textCopyButton.clicked.connect(self.copyText)
        textPasteButton.clicked.connect(self.pasteText)
        htmlCopyButton.clicked.connect(self.copyHtml)
        htmlPasteButton.clicked.connect(self.pasteHtml)
        imageCopyButton.clicked.connect(self.copyImage)
        imagePasteButton.clicked.connect(self.pasteImage)

        self.setLayout(layout)
        self.setWindowTitle('Copy and Paste')

    def copyText(self):
        clipboard = QApplication.clipboard()
        clipboard.setText('hello world')

    def pasteText(self):
        clipboard = QApplication.clipboard()
        self.textLabel.setText(clipboard.text())

    def copyImage(self):
        clipboard = QApplication.clipboard()
        clipboard.setPixmap(QPixmap('./python.png'))

    def pasteImage(self):
        clipboard = QApplication.clipboard()
        self.textLabel.setPixmap(clipboard.pixmap())

    def copyHtml(self):
        mimedata = QMimeData()
        mimedata.setHtml('<b>Bold and <font color=red>Red</font></b>')
        clipboard = QApplication.clipboard()
        clipboard.setMimeData(mimedata)

    def pasteHtml(self):
        clipboard = QApplication.clipboard()
        mimedata = clipboard.mimeData()
        if mimedata.hasHtml():
            self.textLabel.setText(mimedata.html())

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = ClipBoard()
    ex.show()
    sys.exit(app.exec_())